Skip to content

Add service provider discovery for time zone providers - #834

Open
bokken wants to merge 1 commit into
JodaOrg:mainfrom
bokken:spi
Open

Add service provider discovery for time zone providers#834
bokken wants to merge 1 commit into
JodaOrg:mainfrom
bokken:spi

Conversation

@bokken

@bokken bokken commented Aug 5, 2026

Copy link
Copy Markdown

Allow DateTimeZone Provider and NameProvider implementations to be discovered from META-INF/services files

System-property providers retain priority and fail strictly when invalid.
SPI providers are tried in discovery order, with unusable implementations skipped before falling back to the existing defaults.

The goal is to make it easier to leverage the JDK provide ZoneRules (as described here #491) with assembly management only.

Summary by CodeRabbit

  • New Features

    • Date-time zone providers can now be discovered through standard service-provider configuration files.
    • Name providers support the same service-provider discovery mechanism.
    • Existing system-property configuration remains the highest-priority option.
  • Bug Fixes

    • Invalid or unavailable service providers are safely ignored, allowing the next valid provider or built-in default to be used.
    • Provider loading now handles malformed declarations and resource-loading failures more reliably.
  • Documentation

    • Added a release note for version 2.15.0.

Allow DateTimeZone Provider and NameProvider implementations to be
discovered from META-INF/services files

System-property providers retain priority and fail strictly when
invalid.
SPI providers are tried in discovery order, with unusable
implementations skipped before falling back to the existing defaults.
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d9874c6c-2b99-4f31-8005-7290b35ef2e0

📥 Commits

Reviewing files that changed from the base of the PR and between d1ee10e and 6a946b8.

📒 Files selected for processing (9)
  • src/changes/changes.xml
  • src/main/java/org/joda/time/DateTimeZone.java
  • src/main/java/org/joda/time/ServiceProviderLoader.java
  • src/test/java/org/joda/time/TestAll.java
  • src/test/java/org/joda/time/TestServiceProviderLoader.java
  • src/test/resources/spi/unusable/META-INF/services/org.joda.time.tz.NameProvider
  • src/test/resources/spi/unusable/META-INF/services/org.joda.time.tz.Provider
  • src/test/resources/spi/valid/META-INF/services/org.joda.time.tz.NameProvider
  • src/test/resources/spi/valid/META-INF/services/org.joda.time.tz.Provider

📝 Walkthrough

Walkthrough

This change adds service-provider discovery for DateTimeZone provider loading and name-provider loading. It introduces a shared SPI loader, updates DateTimeZone fallback logic and documentation, and adds tests, SPI resource fixtures, and a 2.15.0 change log entry.

Changes

Service-provider loading

Layer / File(s) Summary
Shared SPI loader
src/main/java/org/joda/time/ServiceProviderLoader.java
Adds ServiceProviderLoader as a package-private utility. It gives system-property providers precedence, discovers implementations from META-INF/services, validates and instantiates candidates, skips invalid discovered entries with logging, and falls back across class loaders.
DateTimeZone provider selection
src/main/java/org/joda/time/DateTimeZone.java
Updates provider-loading documentation and default-load order. getDefaultProvider and getDefaultNameProvider now use ServiceProviderLoader for system-property and service-declared implementations before later built-in fallbacks.
SPI tests and release note
src/test/java/org/joda/time/TestServiceProviderLoader.java, src/test/java/org/joda/time/TestAll.java, src/test/resources/spi/..., src/changes/changes.xml
Adds SPI-focused tests, test-only provider implementations, valid and unusable META-INF/services fixtures, and suite registration. The tests cover first usable discovery, built-in fallback on SPI failure, system-property precedence, and fatal failure for bad configured providers. The change log records the new discovery support.

Estimated code review effort: 4 (Complex) | ~50 minutes

Sequence Diagram(s)

sequenceDiagram
  participant DateTimeZone
  participant ServiceProviderLoader
  participant ClassLoader
  participant BuiltInProvider

  DateTimeZone->>ServiceProviderLoader: load Provider or NameProvider
  alt system property is set
    ServiceProviderLoader->>ClassLoader: load configured class
    ClassLoader-->>ServiceProviderLoader: provider instance or error
    ServiceProviderLoader-->>DateTimeZone: validated provider or RuntimeException
  else system property is not set
    ServiceProviderLoader->>ClassLoader: scan META-INF/services
    ClassLoader-->>ServiceProviderLoader: declared provider classes
    ServiceProviderLoader-->>DateTimeZone: first valid discovered provider or null
    alt no valid discovered provider
      DateTimeZone->>BuiltInProvider: use built-in fallback
      BuiltInProvider-->>DateTimeZone: default provider
    end
  end
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: service provider discovery for time zone providers.
Description check ✅ Passed The description explains the SPI discovery behaviour, provider precedence, failure handling, fallback behaviour, and intended goal.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant